#!/usr/bin/env python

from __future__ import print_function
import argparse
import os
import sys
import string

class Levels:
    levels_dir = ""
    doc_wd_level = {}
    def __init__(self, levels_dir):
         
        self.levels_dir = levels_dir
        if not os.path.exists(self.levels_dir):
            print("Error: %s  doesn't exist!" % self.levels_dir, file=sys.stderr)
            sys.exit(1)
        with open(self.levels_dir) as fr:
            # read the mode.levels file, construct dictionary with pair like:
            # {key:docid, value:word-level}
            lines = fr.readlines()
            for docid in range(len(lines)):
                # word:level array for every docs in topic
                self.doc_wd_level[str(docid)] = string.split(lines[docid], ' ') 
        print("[%s] loaded!" % self.levels_dir , file=sys.stdout)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='stupid levels analysis script for hlda result')
    parser.add_argument('--levels', type=str, required=True, help='path for mode.levels')
    args = parser.parse_args()

    levels = Levels(args.levels)
    print("levels analysis done!", file=sys.stdout)
